<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>wasm-vips testsuite</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!-- FIXME(kleisauke): https://github.com/cdnjs/tools/issues/285 -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/11.7.2/mocha.css" crossorigin="anonymous">
  <link rel="modulepreload" href="helpers.js">
  <!-- FIXME(kleisauke): https://github.com/cdnjs/packages/issues/1748 -->
  <link rel="modulepreload" href="https://cdnjs.cloudflare.com/ajax/libs/chai/5.3.0/chai.js" crossorigin="anonymous">
  <style>
    html,
    body {
      width: 100%;
      height: 100%;
      margin: 0;
    }

    :root {
      --mocha-test-pass-color: forestgreen;
    }

    #mocha-stats {
      font-size: initial;
    }

    #mocha h1 {
      font-size: 23px;
      font-weight: initial;
    }

    #mocha .suite .suite h1 {
      font-size: 18px;
    }

    #mocha h2 {
      font-size: 16px;
      font-weight: initial;
      cursor: default;
    }

    #mocha .test.pass .duration {
      font-size: 13px;
    }

    #mocha .test.fail::before {
      font-size: initial;
    }

    #mocha .test.pass::before {
      content: '\2714';
      font-size: initial;
    }

    #mocha .test.pending::before {
      content: '\25CF';
      font-size: initial;
    }

    #mocha .test.pending:hover h2::after {
      content: ' (skipped)'
    }

    #mocha .test pre:not(.error) {
      display: none !important;
    }
  </style>
</head>
<body>
<div id="mocha"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/11.7.2/mocha.min.js" crossorigin="anonymous"></script>
<script class="mocha-init">
  mocha.setup({
    ui: 'bdd',
    slow: 5000,
    timeout: 60000
  });
</script>
<script src="lib/vips.js"></script>
<script type="module" src="test_arithmetic.js"></script>
<script type="module" src="test_auto_delete.js"></script>
<script type="module" src="test_block.js"></script>
<script type="module" src="test_colour.js"></script>
<script type="module" src="test_connection.js"></script>
<script type="module" src="test_conversion.js"></script>
<script type="module" src="test_convolution.js"></script>
<script type="module" src="test_create.js"></script>
<script type="module" src="test_draw.js"></script>
<script type="module" src="test_foreign.js"></script>
<script type="module" src="test_histogram.js"></script>
<script type="module" src="test_iofuncs.js"></script>
<script type="module" src="test_morphology.js"></script>
<script type="module" src="test_mosaicing.js"></script>
<script type="module" src="test_resample.js"></script>
<script type="module" class="mocha-exec">
  /* global Vips */

  // Uncomment to test the web ES6 module
  // import Vips from './lib/vips-es6.js';

  import * as Helpers from './helpers.js';
  import { expect } from 'https://cdnjs.cloudflare.com/ajax/libs/chai/5.3.0/chai.js';

  // Global variables used throughout the unit tests
  globalThis.expect = expect;

  const options = {
    print: (stdout) => console.log(stdout.replace(/\033\[[0-9;]*m/g, '')),
    // Avoid using the browser's image decoder to decode preloaded files
    noImageDecoding: true,
    // Uncomment to disable dynamic modules
    // dynamicLibraries: [],
    // Test all available dynamic modules
    dynamicLibraries: ['vips-jxl.wasm', 'vips-heif.wasm', 'vips-resvg.wasm'],
    preRun: (module) => {
      module.setAutoDeleteLater(true);
      module.setDelayFunction(fn => {
        globalThis.cleanup = fn;
      });

      // Handy for debugging
      // module.ENV.VIPS_INFO = 1;
      // module.ENV.VIPS_LEAK = 1;

      // Preload test files
      for (const file of Helpers.testFiles) {
        module.FS.createPreloadedFile('/', file.split('/').pop(), 'test/unit/images/' + file, true, false);
      }
    },
    postRun: (module) => {
      const pad = 30;
      const have = (name) => module.Utils.typeFind('VipsOperation', name) !== 0;

      console.log('vips version:'.padEnd(pad), module.version());
      console.log('Emscripten version:'.padEnd(pad), module.emscriptenVersion());
      // console.log(module.config());
      console.log('Concurrency:'.padEnd(pad), module.concurrency());

      console.log('Cache max mem:'.padEnd(pad), module.Cache.maxMem());
      console.log('Cache max operations:'.padEnd(pad), module.Cache.max());
      console.log('Cache current operations:'.padEnd(pad), module.Cache.size());
      console.log('Cache max open files:'.padEnd(pad), module.Cache.maxFiles());

      console.log('Memory allocations:'.padEnd(pad), module.Stats.allocations());
      console.log('Memory currently allocated:'.padEnd(pad), module.Stats.mem());
      console.log('Memory high water:'.padEnd(pad), module.Stats.memHighwater());
      console.log('Open files:'.padEnd(pad), module.Stats.files());

      console.log('JPEG support:'.padEnd(pad), have('jpegload') ? 'yes' : 'no');
      console.log('JPEG XL support:'.padEnd(pad), have('jxlload') ? 'yes' : 'no');
      console.log('AVIF support:'.padEnd(pad), have('heifload') ? 'yes' : 'no');
      console.log('PNG support:'.padEnd(pad), have('pngload') ? 'yes' : 'no');
      console.log('TIFF support:'.padEnd(pad), have('tiffload') ? 'yes' : 'no');
      console.log('WebP support:'.padEnd(pad), have('webpload') ? 'yes' : 'no');
      console.log('GIF support:'.padEnd(pad), have('gifload') ? 'yes' : 'no');

      console.log('SVG load:'.padEnd(pad), have('svgload') ? 'yes' : 'no');

      console.log('Text rendering support:'.padEnd(pad), have('text') ? 'yes' : 'no');
    }
  };

  globalThis.vips = await Vips(options);
  mocha.run();
</script>
</body>
</html>
